package com.whynot.frame.manythread.producerandcusumer;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;

import com.whynot.frame.manythread.producerandcusumer.comsume.Comsume;
import com.whynot.frame.manythread.producerandcusumer.entities.Data;
import com.whynot.frame.manythread.producerandcusumer.product.Product;

/**
 * 描    述: 队列机制
 * 创建时间: 2018/12/24
 */
public class Client {

	public static void main(String[] args) {
		BlockingDeque<Data> qeque = new LinkedBlockingDeque<Data>(10);
		
		Product product1 = new Product(qeque);
		Product product2 = new Product(qeque);
		Product product3 = new Product(qeque);
		Comsume comsume1 = new Comsume(qeque);
		Comsume comsume2 = new Comsume(qeque);
		Comsume comsume3 = new Comsume(qeque);
		
		ExecutorService service = Executors.newCachedThreadPool();
		service.execute(product1);
		service.execute(product2);
		service.execute(product3);
		service.execute(comsume1);
		service.execute(comsume2);
		service.execute(comsume3);
		
		try {
			Thread.sleep(10000);
		
		
			product1.stop();
			product2.stop();
			product3.stop();
			
			Thread.sleep(3000);
			service.shutdown();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
